package fr.inria.phoenix.scenario.bwsnfirefighting.framework.distributed.manualbutton;

import java.util.HashMap;

import fr.inria.diagen.core.ServiceConfiguration;
import fr.inria.diagen.core.exception.DiaGenException;
import fr.inria.diagen.core.exception.InvocationException;
import fr.inria.diagen.core.network.RemoteServiceInfo;
import fr.inria.diagen.core.service.local.Service;

import java.lang.Boolean;
import fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location;

import fr.inria.diagen.core.module.command.ICommandListener;

/**
 * Define a manual button device which can send an alarm through the source activated
 *
 * @[33,0]
 * device ManualButton extends LocatedDevice {
 *   source activated as Boolean;
 * }
 */
public abstract class ManualButton extends Service implements ICommandListener {

  /**
     * @param serviceConfiguration
     */
    public ManualButton(ServiceConfiguration serviceConfiguration , fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location location) {
      super("ManualButton", serviceConfiguration, GeneratedFramework.getInstance());
      setLocation(location);
    }

    @Override
    public final HashMap<String, Object> getAttributes() {
        HashMap<String, Object> attributes = new HashMap<String, Object>();
    
        attributes.put("location",location);

        return attributes;
    }
    
    private fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location location;

    /**
     * @[29,11]
     * attribute location as Location;
     * @param newLocationValue
     */
    protected void setLocation(fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location newLocationValue) {
      if (location != newLocationValue) {
        location = newLocationValue;
        updateAttributes();
      }
    }

    /**
     * @[29,11]
     * attribute location as Location;
     * @return
     */  
    public fr.inria.phoenix.scenario.bwsnfirefighting.framework.datatype.Location getLocation() {
      return location;
    }

	protected final void _postInitialize() {postInitialize();}
	
	/**
	 *
	 */
	protected void postInitialize() {}

  
    public final Object commandReceived(RemoteServiceInfo rsi, String methodName, Object... args) throws DiaGenException {

    if (methodName.equals("getActivated")) {
      return getActivated();
    }
    
      throw new InvocationException("Undefined method name " + methodName);
    }
  

    private java.lang.Boolean activated;
    /**
     * @[34,1]
     * source activated as Boolean;
     */  
    protected void setActivated(java.lang.Boolean newActivatedValue ) {
      activated = newActivatedValue;
      getServer().publish("activated", newActivatedValue); 
    }

    /**
     * @[34,1]
     * source activated as Boolean;
     */
    protected java.lang.Boolean getActivated() {
      return activated;    }
 
}